package comp.wxapi.utils;

import java.util.Random;
import java.util.UUID;

public class UUIDUtils {
	
	public static final int DEFAULT_LENGTH = 11;
	
	public static String upperCaseUUID() {
		
		return lowerCaseUUID().toUpperCase();
	}
	
	public static String lowerCaseUUID() {
		
		return UUID.randomUUID().toString().replaceAll("-", "");
	}
	
	public static String numberString(Integer len) {
		if(len == null || len == 0) {
			len = DEFAULT_LENGTH;
		}
		Random ran = new Random();
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < len; i++) {
			buffer.append(ran.nextInt(10));
		}
		return buffer.toString();
	}
	
	public static String randomNumber(Integer len) {
		if(len == null || len == 0) len = DEFAULT_LENGTH;
		String str = String.valueOf(System.currentTimeMillis());
		Integer curLen = str.length();
		Integer cz = curLen-len;
		if(cz == 0) {
			return str;
		}
		
		if(cz > 0) {
			return str.substring(0, len);
		}
		Random ran = new Random();
		for (int i = 0; i > cz ; i--) {
			str += ""+ran.nextInt(10);
		}
		
		return str;
	}
	
	public static void main(String[] args) {
//		String str = "https://console.xcaas.com/service/cloud/tencentapi/callback";
//		try {
//			System.out.println(URLEncoder.encode(str,"UTF-8"));
//		} catch (UnsupportedEncodingException e) {
//			e.printStackTrace();
//		}
	}
}
